﻿@* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@
@using System
@using Hangfire
@using Hangfire.Dashboard
@using Hangfire.Dashboard.Pages
@using Hangfire.Dashboard.Resources
@inherits RazorPage
@{
    Layout = new LayoutPage(Strings.SucceededJobsPage_Title);

    int from, perPage;

    int.TryParse(Query("from"), out from);
    int.TryParse(Query("count"), out perPage);

    var monitor = Storage.GetMonitoringApi();
    var pager = new Pager(from, perPage, monitor.SucceededListCount());
    var succeededJobs = monitor.SucceededJobs(pager.FromRecord, pager.RecordsPerPage);
}

<div class="row">
    <div class="col-md-3">
        @Html.JobsSidebar()
    </div>
    <div class="col-md-9">
        <h1 class="page-header">@Strings.SucceededJobsPage_Title</h1>

        @if (pager.TotalPageCount == 0)
        {
            <div class="alert alert-info">
                @Strings.SucceededJobsPage_NoJobs
            </div>
        }
        else
        {
            <div class="js-jobs-list">
                <div class="btn-toolbar btn-toolbar-top">
                    @if (!IsReadOnly)
                    {
                        <button class="js-jobs-list-command btn btn-sm btn-primary"
                                data-url="@Url.To("/jobs/succeeded/requeue")"
                                data-loading-text="@Strings.Common_Enqueueing"
                                disabled="disabled">
                            <span class="glyphicon glyphicon-repeat"></span>
                            @Strings.Common_RequeueJobs
                        </button>
                    }
                    @Html.PerPageSelector(pager)
                </div>

                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                @if (!IsReadOnly)
                                {
                                    <th class="min-width">
                                        <input type="checkbox" class="js-jobs-list-select-all"/>
                                    </th>
                                }
                                <th class="min-width">@Strings.Common_Id</th>
                                <th>@Strings.Common_Job</th>
                                <th class="min-width">@Strings.SucceededJobsPage_Table_TotalDuration</th>
                                <th class="align-right">@Strings.SucceededJobsPage_Table_Succeeded</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var job in succeededJobs)
                            {
                                <tr class="js-jobs-list-row @(job.Value == null || !job.Value.InSucceededState ? "obsolete-data" : null) @(job.Value != null && job.Value.InSucceededState ? "hover" : null)">
                                    @if (!IsReadOnly)
                                    {
                                        <td>
                                            @if (job.Value == null || job.Value.InSucceededState)
                                            {
                                                <input type="checkbox" class="js-jobs-list-checkbox" name="jobs[]" value="@job.Key"/>
                                            }
                                        </td>
                                    }
                                    <td class="min-width">
                                        @Html.JobIdLink(job.Key)
                                        @if (job.Value != null && !job.Value.InSucceededState)
                                        {
                                            <span title="@Strings.Common_JobStateChanged_Text" class="glyphicon glyphicon-question-sign"></span>
                                        }
                                    </td>

                                    @if (job.Value == null)
                                    {
                                        <td colspan="3">
                                            <em>@Strings.Common_JobExpired</em>
                                        </td>
                                    }
                                    else
                                    {
                                        <td class="word-break">
                                            @Html.JobNameLink(job.Key, job.Value.Job)
                                        </td>
                                        <td class="min-width align-right">
                                            @if (job.Value.TotalDuration.HasValue)
                                            {
                                                @Html.ToHumanDuration(TimeSpan.FromMilliseconds(job.Value.TotalDuration.Value), false)
                                            }
                                        </td>
                                        <td class="min-width align-right">
                                            @if (job.Value.SucceededAt.HasValue)
                                            {
                                                @Html.RelativeTime(job.Value.SucceededAt.Value)
                                            }
                                        </td>
                                    }
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>

                @Html.Paginator(pager)
            </div>
        }
    </div>
</div>